package com.zsk.shop.controller.gop;

import com.zsk.shop.common.base.BaseResponse;
import com.zsk.shop.model.params.AddShopAppVersionParams;
import com.zsk.shop.model.params.EditShopAppVersionParams;
import com.zsk.shop.model.params.GopShopAppVersionListParams;
import com.zsk.shop.model.results.GopShopAppVersionListResult;
import com.zsk.shop.service.ShopAppVersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * app版本管理管理控制器
 */
@RestController
@Api(tags = "GOP中app的版本管理")
@RequestMapping("/gop/appVersion")
public class GopAppVersionController {

    @Autowired
    private ShopAppVersionService shopAppVersionService;

    @PostMapping("/addAppVersion.do")
    @ApiOperation("gop新增版本")
    public BaseResponse addAppVersion(@RequestBody @Validated AddShopAppVersionParams params) {
        return shopAppVersionService.addAppVersion(params);
    }

    @PostMapping("/versionUpdate.do")
    @ApiOperation("gop修改版本内容")
    public BaseResponse versionUpdate(@RequestBody @Validated EditShopAppVersionParams params) {
        return shopAppVersionService.editAppVersion(params);
    }

    @GetMapping("/changePublishById.do")
    @ApiOperation("gop修改是否发布")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "版本编号"),
            @ApiImplicitParam(name = "toPublish", value = "true-发布,false-修改为下架（未发布）")})
    public BaseResponse changePublishById(Long id, Boolean toPublish) {
        return shopAppVersionService.changePublishById(id, toPublish);
    }

    @GetMapping("/delete.do")
    @ApiOperation("gop删除版本")
    @ApiImplicitParam(name = "id", value = "版本编号")
    public BaseResponse deleteById(Long id) {
        return shopAppVersionService.deleteById(id);
    }

    @ApiOperation("gop版本列表")
    @GetMapping("/GopYlAppVersionList.do")
    @ApiImplicitParams({@ApiImplicitParam(name = "key", value = "版本名称/版本"),
            @ApiImplicitParam(name = "platform", value = "版本类型 \"1\":苹果 \"2\":安卓 \"\"/不传是所有"),
            @ApiImplicitParam(name = "isPublish", value = "版本状态 \"1/true\"已发布 \"false\"未发布 \"\"/不传是所有"),
            @ApiImplicitParam(name = "limit"), @ApiImplicitParam(name = "page")})
    public BaseResponse<GopShopAppVersionListResult> GopYlAppVersionList(String key, String platform, String isPublish) {
        GopShopAppVersionListParams params = GopShopAppVersionListParams.builder()
                .key(key).platform(platform).isPublish(isPublish).build();
        return shopAppVersionService.GopYlAppVersionList(params);
    }

}
